home *** CD-ROM | disk | FTP | other *** search
/ Saar AMOK 2 / Saar AMOK II - Oktober 1994 (1994)(Kreativ Marketing)(DE)[!][I-7598].iso / tools / amigaguide / ag_v39 / source / hyperbrowser / main.c < prev    next >
C/C++ Source or Header  |  1993-01-08  |  6KB  |  192 lines

  1. /* main.c
  2.  * Written by David N. Junod
  3.  *
  4.  * (c) Copyright 1992 Commodore-Amiga, Inc.  All rights reserved.
  5.  *
  6.  * This software is provided as-is and is subject to change; no warranties
  7.  * are made.  All use is at your own risk.  No liability or responsibility
  8.  * is assumed.
  9.  *
  10.  */
  11.  
  12. #include "hyperbrowser.h"
  13.  
  14. /*****************************************************************************/
  15.  
  16. int main (void)
  17. {
  18.     struct ExecBase *SysBase = (*((struct ExecBase **) 4));
  19.     LONG failureLevel = RETURN_FAIL;
  20.     struct WBStartup *wbMsg = NULL;
  21.     struct GlobalData *gd = NULL;
  22.     LONG failureCode = 0;
  23.     struct Process *pr;
  24.     UBYTE name[64];
  25.     BPTR fh;
  26.  
  27.     pr = (struct Process *) SysBase->ThisTask;
  28.     if (!(pr->pr_CLI))
  29.     {
  30.     WaitPort (&pr->pr_MsgPort);
  31.     wbMsg = (struct WBStartup *) GetMsg (&pr->pr_MsgPort);
  32.     }
  33.  
  34.     /* Make sure we are running with V39 or greater */
  35.     if (SysBase->LibNode.lib_Version < 39)
  36.     {
  37.     /* DOS isn't open!!!! */
  38.     vprintf (gd, "requires V39\n", NULL);
  39.     }
  40.     /* Allocate our global data */
  41.     else if (gd = AllocVec (sizeof (struct GlobalData), MEMF_CLEAR))
  42.     {
  43.     /* Open the ROM libraries */
  44.     DOSBase       = OpenLibrary ("dos.library", 39);
  45.     IntuitionBase = OpenLibrary ("intuition.library", 39);
  46.     GfxBase       = OpenLibrary ("graphics.library", 39);
  47.     UtilityBase   = OpenLibrary ("utility.library", 39);
  48.  
  49.     /* Our process */
  50.     gd->gd_Process = pr = (struct Process *) FindTask (NULL);
  51.  
  52.     /* Initialize the node host hook */
  53.     gd->gd_NHHook.h_Entry = nodehost;
  54.     gd->gd_NHHook.h_Data = gd;
  55.  
  56.     /* Open AmigaGuide */
  57.     if (AmigaGuideBase = OpenLibrary ("amigaguide.library", 33))
  58.     {
  59.         /* Build the unique name */
  60.         gd->gd_NHID = GetUniqueID ();
  61.         sprintf (gd->gd_NHName, "%s.%ld", BASENAME, gd->gd_NHID);
  62.  
  63.         /* Create the temporary guide file */
  64.         sprintf (name, "T:%s.guide", gd->gd_NHName);
  65.         if (fh = Open (name, MODE_NEWFILE))
  66.         {
  67.         /* Create the database */
  68.         vfprintf (gd, fh, "@database %s.guide\n\n", (void *) gd->gd_NHName);
  69.         vfprintf (gd, fh, "@node Main HyperBrowser\n", NULL);
  70.         vfprintf (gd, fh, "\nExec Lists\n\n", NULL);
  71.         vfprintf (gd, fh, "  @{\"Resource\" link HYPERNOZY.RESOURCELIST}\n", NULL);
  72.         vfprintf (gd, fh, "  @{\"Device\" link HYPERNOZY.DEVICELIST}\n", NULL);
  73.         vfprintf (gd, fh, "  @{\"Interrupt\" link HYPERNOZY.INTRLIST}\n", NULL);
  74.         vfprintf (gd, fh, "  @{\"Library\" link HYPERNOZY.LIBRARYLIST}\n", NULL);
  75.         vfprintf (gd, fh, "  @{\"Port\" link HYPERNOZY.PORTLIST}\n", NULL);
  76.         vfprintf (gd, fh, "  @{\"TaskReady\" link HYPERNOZY.TASKREADYLIST}\n", NULL);
  77.         vfprintf (gd, fh, "  @{\"TaskWait\" link HYPERNOZY.TASKWAITLIST}\n\n", NULL);
  78.         vfprintf (gd, fh, "Intuition Lists\n\n", NULL);
  79.         vfprintf (gd, fh, "  @{\"Class\" link HYPERNOZY.CLASSLIST}\n", NULL);
  80.         vfprintf (gd, fh, "  @{\"Screen\" link HYPERNOZY.SCREENLIST}\n", NULL);
  81.         vfprintf (gd, fh, "@endnode\n", NULL);
  82.  
  83.         /* Close it */
  84.         Close (fh);
  85.  
  86.         /* Start the Dynamic Node Host */
  87.         gd->gd_NH = AddAmigaGuideHostA (&gd->gd_NHHook, gd->gd_NHName, NULL);
  88.  
  89.         /* Lock the default public screen */
  90.         if (gd->gd_Screen = LockPubScreen (NULL))
  91.         {
  92.             /* We don't want the window to automatically activate */
  93.             gd->gd_NAG.nag_Flags = HTF_NOACTIVATE;
  94.  
  95.             /* Set the document name */
  96.             gd->gd_NAG.nag_Name = name;
  97.  
  98.             /* Set the screen */
  99.             gd->gd_NAG.nag_Screen = gd->gd_Screen;
  100.  
  101.             /* Set the application base name */
  102.             gd->gd_NAG.nag_ClientPort = gd->gd_NAG.nag_BaseName = BASENAME;
  103.  
  104.             /* Open the help system */
  105.             if (gd->gd_AmigaGuide = openamigaguide (gd, &gd->gd_NAG,
  106.                                 AGA_HelpGroup, gd->gd_NHID,
  107.                                 TAG_DONE))
  108.             {
  109.             /* Show that we are OK */
  110.             failureLevel = RETURN_OK;
  111.  
  112.             /* Close the help system */
  113.             CloseAmigaGuide (gd->gd_AmigaGuide);
  114.             }
  115.             else
  116.             {
  117.             DisplayError (gd, pr->pr_Result2);
  118.             }
  119.  
  120.             /* Unlock the default public screen */
  121.             UnlockPubScreen (NULL, gd->gd_Screen);
  122.         }
  123.  
  124.         /* Remove the dynamic node host */
  125.         while (RemoveAmigaGuideHostA (gd->gd_NH, NULL) > 0)
  126.             Delay (10);
  127.  
  128.         /* Delete the temporary file */
  129.         DeleteFile (name);
  130.         }
  131.  
  132.         /* Close AmigaGuide */
  133.         CloseLibrary (AmigaGuideBase);
  134.     }
  135.  
  136.     /* Close the ROM libraries */
  137.     CloseLibrary (UtilityBase);
  138.     CloseLibrary ((struct Library *) GfxBase);
  139.     CloseLibrary ((struct Library *) IntuitionBase);
  140.     CloseLibrary (DOSBase);
  141.  
  142.     FreeVec (gd);
  143.     }
  144.  
  145.     if (wbMsg)
  146.     {
  147.     Forbid ();
  148.     ReplyMsg ((struct Message *) wbMsg);
  149.     }
  150.     pr->pr_Result2 = failureCode;
  151.     return (failureLevel);
  152. }
  153.  
  154. /*****************************************************************************/
  155.  
  156. APTR openamigaguide (struct GlobalData * gd, struct NewAmigaGuide * nag, Tag tag1,...)
  157. {
  158.     if (AmigaGuideBase->lib_Version > 33)
  159.     return OpenAmigaGuideA (nag, (struct TagItem *) & tag1);
  160.     else
  161.     return OpenAmigaGuideA (nag, NULL);
  162. }
  163.  
  164. /*****************************************************************************/
  165.  
  166. void bprintf (struct GlobalData *gd, STRPTR fmt, void *arg1, ...)
  167. {
  168.     asprintf (gd->gd_Buffer, fmt, &arg1);
  169.     strcat (gd->gd_Node, gd->gd_Buffer);
  170. }
  171.  
  172. /*****************************************************************************/
  173.  
  174. void vprintf (struct GlobalData * gd, STRPTR fmt, void *arg1,...)
  175. {
  176.     VPrintf (fmt, (LONG *) & arg1);
  177. }
  178.  
  179. /*****************************************************************************/
  180.  
  181. void vfprintf (struct GlobalData * gd, BPTR fh, STRPTR fmt, void *arg1,...)
  182. {
  183.     VFPrintf (fh, fmt, (LONG *) & arg1);
  184. }
  185.  
  186. /*****************************************************************************/
  187.  
  188. VOID DisplayError (struct GlobalData * gd, LONG err)
  189. {
  190.     vprintf (gd, "%s\n", (void *) GetAmigaGuideString (err));
  191. }
  192.